package com.leetcode.LC;

public class LC997 {
    public int findJudge(int N, int[][] trust) {
        //用一个二维数组记录每个结点的入度和出度，出度为0入度为N的就是法官
        int[][] ints = new int[N][2];

        for (int i = 0; i < trust.length; i++) {
            ints[trust[i][0]-1][0]++;//小镇人是从1开始的所以trust[i][0]-1作为行坐标
            ints[trust[i][1]-1][1]++;
        }
        for (int i = 0; i < ints.length; i++) {
            if (ints[i][0]==0&&ints[i][1]==N-1){//法官不相信自己所以N-1
                return i+1;
            }
        }
        return -1;
    }

}
